unit Main;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Label1: TLabel;
    EditX0: TLabeledEdit;
    EditY0: TLabeledEdit;
    EditX1: TLabeledEdit;
    EditY1: TLabeledEdit;
    ComboBoxLX: TComboBox;
    EditInc: TLabeledEdit;
    ButtonGenTWLine: TButton;
    EditCount: TLabeledEdit;
    ButtonColor: TButton;
    ColorDialog1: TColorDialog;
    LabelColor: TLabel;
    ComboBoxColor: TComboBox;
    ComboBoxColor2: TComboBox;
    LabelColor2: TLabel;
    ButtonColor2: TButton;
    CheckBoxColor2: TCheckBox;
    ButtonGenSJ: TButton;
    EditSJ1: TLabeledEdit;
    EditSJ2: TLabeledEdit;
    EditSJ3: TLabeledEdit;
    EditSJ4: TLabeledEdit;
    EditSJ5: TLabeledEdit;
    EditSJ6: TLabeledEdit;
    procedure ButtonGenTWLineClick(Sender: TObject);
    procedure ButtonColorClick(Sender: TObject);
    procedure ComboBoxLXChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ComboBoxColorChange(Sender: TObject);
    procedure ButtonColor2Click(Sender: TObject);
    procedure ComboBoxColor2Change(Sender: TObject);
    procedure ButtonGenSJClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ButtonGenTWLineClick(Sender: TObject);
var
  i,iX0,iX1,iY1,iY0,iInc,iSL,iLX,iColor : Integer;
  sText,sColor : string;
begin
  iX0 := StrToIntDef(EditX0.Text,0);
  iY0 := StrToIntDef(EditY0.Text,0);

  iX1 := StrToIntDef(EditX1.Text,0);
  iY1 := StrToIntDef(EditY1.Text,0);

  iInc := StrToIntDef(EditInc.Text,0);
  iSL := StrToIntDef(EditCount.Text,0);

  iLX := ComboBoxLX.ItemIndex;
  iColor := LabelColor.Color;

  Memo1.Lines.Clear;
  for i :=0 to iSL -1 do
  begin
    iColor := LabelColor.Color;
    if i  mod 5 =0 then
    begin
      if CheckBoxColor2.Checked then
        iColor := LabelColor2.Color;
      Memo1.Lines.Add('');
    end;

    if ComboBoxLX.ItemIndex = 0 then   //X
    begin
      iY1 := iY0 + i * iInc;
      sText := Format('    (B:(X:%d;Y:%d);E:(X:%d;Y:%d);Color:%d),',[iX0,iY1,iX1,iY1,iColor]);
    end
    else
    begin                              //Y
      iX1 := iX0 + i * iInc;
      sText := Format('    (B:(X:%d;Y:%d);E:(X:%d;Y:%d);Color:%d),',[iX1,iY0,iX1,iY1,iColor]);
    end;

    Memo1.Lines.Add(sText);

  end;
end;

procedure TForm1.ComboBoxLXChange(Sender: TObject);
begin
  EditY1.Enabled := ComboBoxLX.ItemIndex = 1;
  EditX1.Enabled := ComboBoxLX.ItemIndex = 0;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ComboBoxLXChange(nil);
end;

procedure TForm1.ComboBoxColorChange(Sender: TObject);
begin
  case ComboBoxColor.ItemIndex of
    0 : LabelColor.Color := clBlack;
    1 : LabelColor.Color := clRed;
    2 : LabelColor.Color := clBlue;
    3 : LabelColor.Color := clGray;
    4 : LabelColor.Color := clTeal;
    5 : LabelColor.Color := clSilver;
  end;
end;

procedure TForm1.ButtonColorClick(Sender: TObject);
begin
  ColorDialog1.Color := LabelColor.Color;
  if ColorDialog1.Execute then
    LabelColor.Color := ColorDialog1.Color;
end;

procedure TForm1.ButtonColor2Click(Sender: TObject);
begin
  ColorDialog1.Color := LabelColor2.Color;
  if ColorDialog1.Execute then
    LabelColor2.Color := ColorDialog1.Color;
end;

procedure TForm1.ComboBoxColor2Change(Sender: TObject);
begin
  case ComboBoxColor2.ItemIndex of
    0 : LabelColor2.Color := clBlack;
    1 : LabelColor2.Color := clRed;
    2 : LabelColor2.Color := clBlue;
    3 : LabelColor2.Color := clGray;
    4 : LabelColor2.Color := clTeal;
    5 : LabelColor2.Color := clSilver;
  end;
end;

procedure TForm1.ButtonGenSJClick(Sender: TObject);
var
  i,iX,iX0,iY0,iInc,iSL,iIndex : Integer;
  sText,sFont,sSJ : string;
const
  SJ : array[0..5] of string = ('3','7','11','15','19','23');
  Font : array[0..5] of string = ('tfSJR','tfSJB','tfSJB','tfSJB','tfSJR','tfSJR');
begin
  //
  iX0 := StrToIntDef(EditX0.Text,0);
  iY0 := StrToIntDef(EditY0.Text,0);
  iInc := StrToIntDef(EditInc.Text,0);
  iSL := StrToIntDef(EditCount.Text,0);


  Memo1.Lines.Clear;
  for i := 0 to iSL-1 do
  begin
    iIndex := i  mod 6;
    sSJ := SJ[iIndex];
    sFont := Font[iIndex];

    if iIndex =0 then
      Memo1.Lines.Add('');

    if Length(sSJ)=2 then
      iX := iX0 + i * iInc -2
    else
      iX := iX0 + i * iInc;

    sText := Format('    (P:(X:%d;Y:%d);Text:''%s'';Font:%s),',[iX,iY0,sSJ,sFont]);
    Memo1.Lines.Add(sText);

  end;
  
end;

end.
